package img;

import util.FileCreator;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @description:
 * @author: 张德长 dechang.zhang@ucarinc.com
 * @date: 10:51:54 2018/11/16
 * @version:2.0
 */
public class Test {
    public static int[] pisitionC1 = {328, 372, 490, 1313};//C1
    public static int[] pisitionC3 = {328 + 220, 372, 270, 1313};//C3
    public static int[] pisitionC6 = {328 + 220 + 220, 372, 51, 1313};//C6
    public static int[] pisitionC2 = {328, 1133, 490, 552};//C2
    public static int[] pisitionC5 = {328 + 220, 1133, 270, 552};//C5
    // right 84  buttom 23 top
    public static int timeTop = 28;
    public static int timeLeft = 80;
    public static int timeBottom = 137;
    public static int timeRight = 104;
    public static int mTop = 133;
    public static int mLeft = 0;
    public static int mBottom = 23;
    public static int mRight = 84;
    public static int[] timeC1 = {pisitionC1[0] - timeTop, pisitionC1[1] + timeLeft, pisitionC1[2] + timeBottom, pisitionC1[3] + timeRight};
    public static int[] timeC2 = {pisitionC2[0] - timeTop, pisitionC2[1] + timeLeft, pisitionC2[2] + timeBottom, pisitionC2[3] + timeRight};
    public static int[] timeC3 = {pisitionC3[0] - timeTop, pisitionC3[1] + timeLeft, pisitionC3[2] + timeBottom, pisitionC3[3] + timeRight};
    public static int[] timeC5 = {pisitionC5[0] - timeTop, pisitionC5[1] + timeLeft, pisitionC5[2] + timeBottom, pisitionC5[3] + timeRight};
    public static int[] timeC6 = {pisitionC6[0] - timeTop, pisitionC6[1] + timeLeft, pisitionC6[2] + timeBottom, pisitionC6[3] + timeRight};

    public static int[] meC1 = {pisitionC1[0] + mTop, pisitionC1[1] + mLeft, pisitionC1[2] - mBottom, pisitionC1[3] - mRight};
    public static int[] meC2 = {pisitionC2[0] + mTop, pisitionC2[1] + mLeft, pisitionC2[2] - mBottom, pisitionC2[3] - mRight};
    public static int[] meC3 = {pisitionC3[0] + mTop, pisitionC3[1] + mLeft, pisitionC3[2] - mBottom, pisitionC3[3] - mRight};
    public static int[] meC5 = {pisitionC5[0] + mTop, pisitionC5[1] + mLeft, pisitionC5[2] - mBottom, pisitionC5[3] - mRight};
    public static int[] meC6 = {pisitionC6[0] + mTop, pisitionC6[1] + mLeft, pisitionC6[2] - mBottom, pisitionC6[3] - mRight};
    public static int[][] positionsMe = {meC1, meC2, meC3, meC5, meC6};
    public static int[][] positionsTime = {timeC1, timeC2, timeC3, timeC5, timeC6};
    public static void main(String[] args) {
        //获取原图
        ImgFile imgBig = new ImgFile("屏幕截图", "20181128165501.png");
        for (int i = 0; i < positionsTime.length; i++) {
            BufferedImage elementSnapShot = AgImgUtil.getPositionBufferedImageNoSelect(imgBig.bufferedImage, positionsTime[i]);
            elementSnapShot = ImgUtil.selectGRB(elementSnapShot, 130);
            File f = FileCreator.checkExist("屏幕截图/ceshishibie.jpg");
            try {
                ImageIO.write(elementSnapShot, "JPEG", f);
            } catch (IOException e) {
                e.printStackTrace();
            }
            String result = tesseract.Test.getResult(f);
            System.out.println(result);
            ImgUtil.savePic(elementSnapShot, "屏幕截图/ceshi" + i + ".jpg");
        }


        /*
        //从屏幕截图获取数据
        BufferedImage bit = AgImgUtil.getPositionBufferedImage(screen, pisitionC1);
        ArrayList listC1 = AgImgUtil.writeSingle(bit);
        bit = AgImgUtil.getPositionBufferedImage(screen, pisitionC2);
        ArrayList listC2 = AgImgUtil.writeSingle(bit);
        bit = AgImgUtil.getPositionBufferedImage(screen, pisitionC3);
        ArrayList listC3 = AgImgUtil.writeSingle(bit);
        bit = AgImgUtil.getPositionBufferedImage(screen, pisitionC5);
        ArrayList listC5 = AgImgUtil.writeSingle(bit);
        bit = AgImgUtil.getPositionBufferedImage(screen, pisitionC6);
        ArrayList listC6 = AgImgUtil.writeSingle(bit);*/

       /* AgImgUtil.printResult(listC1);
        AgImgUtil.printResult(listC2);
        AgImgUtil.printResult(listC3);
        AgImgUtil.printResult(listC5);
        AgImgUtil.printResult(listC6);*/

        // AgStragy.twoTheSame(getArr(c1));


        //ImgUtil.savePic(bit, imgBig.path + "devided_c1" + imgBig.fileName);

/*


        ImgUtil.savePic(bit, imgBig.path + "devided_c1" + imgBig.fileName);

        bit = ImgUtil.devideImg(imgBig.pixels, 430, 1150, 521, 165 + yanLength);
        bit = ImgUtil.selectGRB(bit, target);
        ImgUtil.savePic(bit, imgBig.path + "devided_c2" + imgBig.fileName);

        bit = ImgUtil.devideImg(imgBig.pixels, 648, 389, 300, 926 + yanLength);
        bit = ImgUtil.selectGRB(bit, target);
        ImgUtil.savePic(bit, imgBig.path + "devided_c3" + imgBig.fileName);


        bit = ImgUtil.devideImg(imgBig.pixels, 648, 1150, 300, 165 + yanLength);
        bit = ImgUtil.selectGRB(bit, target);
        ImgUtil.savePic(bit, imgBig.path + "devided_c5" + imgBig.fileName);

        bit = ImgUtil.devideImg(imgBig.pixels, 868, 389, 82, 926 + yanLength);
        bit = ImgUtil.selectGRB(bit, target);
        ImgUtil.savePic(bit, imgBig.path + "devided_c6" + imgBig.fileName);
*/

        /*//灰度处理
        BufferedImage bi = ImgUtil.makeImageColorToBlackWhite(imgBig);
        //黑白处理
        bi = ImgUtil.binaryImage(bi, 99);
        ImgUtil.savePic(bi, imgBig.path + "white_black_" + imgBig.fileName);*/
        //ImgFile imgB = new ImgFile("src/main/resources/tessdata/", "black_testFirst.png");
        //imgB.getRGBNum();

    }
}
